import tkinter as tk
from tkinter import filedialog as fd
from tkinter import messagebox

class application(tk.Frame):
    def __init__(self,master=None):
        self.master=master
        super().__init__(master)
        self.creatWidget()

    def creatWidget(self):
        self.btn=tk.Button(self.master,text='上传文件',command=self.up)
        self.btn.pack()

        self.text=tk.Text(self.master)
        self.text.pack()

    def up(self):
        with fd.askopenfile(filetypes=(('* .txt'),),mode='rb') as f:
            txt=f.read().decode('utf-8')
            self.text.insert(tk.END,txt)


window=tk.Tk()
app=application(window)
window.mainloop()